import 'package:flutter/material.dart';

// 定义有状态组件
// 快捷键：fstfull，得安装插件：Flutter Widget Snippets
class HomePage01 extends StatefulWidget {
  const HomePage01({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage01> {
  // 状态变量
  int count = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('计数器'), backgroundColor: Colors.blue),
      body: Center(child: Text(count.toString())),
      // 悬浮按钮
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          // 更改状态使用setState
          setState(() {
            count++;
          });
        },
        child: Icon(Icons.add),
      ),
    );
  }
}
